﻿@model IEnumerable<EmgrMvc.Models.DeviceGroup>

@{
    ViewData["Title"] = "Index";
}
<script>
    function groupOn(id) {
        $.post("/api/app/group/on/" + id, (resp, status) => {
            if (status == "success")
                alert("设备组开机成功");
        }
        )
    }

    function groupOff(id) {
        $.post("/api/app/group/off/" + id, (resp, status) => {
            if (status == "success")
                alert("设备组关机成功");
        }
        )
    }

</script>
<h2>Index</h2>

<p>
    <a asp-action="Create">Create New</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Description)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
@foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                <a asp-action="Edit" asp-route-id="@item.Id">编辑</a> |
                <a asp-action="Details" asp-route-id="@item.Id">查看</a> |
                <a asp-action="Delete" asp-route-id="@item.Id">删除</a> |
                <a onclick="groupOn(@item.Id)">开机</a> |
                <a onclick="groupOff(@item.Id)">关机</a>
            </td>
        </tr>
}
    </tbody>
</table>
